package sk.upjs.ics.fca.bonds.bruteforce;

import java.util.ArrayList;
import java.util.List;

/**
 * Tato trieda sa stara o generovanie variacii bez opakovania
 * 
 * @author Patrik Mihalcin
 */
public class VariationsWithoutRepetition {
	private int[] array;
	private int n;
	private List<List<List<Double>>> allVariations = new ArrayList<List<List<Double>>>();
	private List<List<Double>> fuzzySets = new ArrayList<List<Double>>();

	/**
	 * Konstruktor prijima ako vstupy zoznam fuzzy mnozin a velkost danej
	 * variacie
	 * 
	 * @param fuzzySets
	 *            zoznam fuzzy mnozin
	 * @param k
	 *            velkost variacie
	 */
	public VariationsWithoutRepetition(List<List<Double>> fuzzySets, int k) {
		this.fuzzySets = fuzzySets;
		this.n = fuzzySets.size();
		array = new int[k];
	}

	private void generate(int fromIndex) {
		if (fromIndex == array.length) {
			List<List<Double>> variation = new ArrayList<List<Double>>();
			for (int i = 0; i < array.length; i++) {
				// we generate indexes starting with 1, that's why -1
				variation.add(fuzzySets.get(array[i] - 1));
			}
			allVariations.add(variation);
			return;
		}

		for (int i = 1; i <= n; i++) {
			array[fromIndex] = i;
			generate(fromIndex + 1);
		}
	}

	/**
	 * Nastartuje generovanie variacii
	 */
	public void generate() {
		generate(0);
	}

	/**
	 * Vrati mnozinu vsetkych variacii vstupneho zoznamu fuzzy mnozin
	 * 
	 * @return mnozina variacii
	 */
	public List<List<List<Double>>> getAllVariations() {
		return allVariations;
	}
}
